<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Overtrue\EasySms\EasySms;

class SmsNotice implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        $config = [
            // HTTP 请求的超时时间（秒）
            'timeout' => 5.0,

            // 默认发送配置
            'default' => [
                // 网关调用策略，默认：顺序调用
                'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

                // 默认可用的发送网关
                'gateways' => [
                     'aliyun'
                ],
            ],
            // 可用的网关配置
            'gateways' => [
                'errorlog' => [
                    'file' => '/tmp/easy-sms.log',
                ],
                'yunpian' => [
                    'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
                ],
                'aliyun' => [
                    'access_key_id' => 'CV207DfFPmNae5TY',
                    'access_key_secret' => 'iVE0dGfv70sKlrlFNN6HiYZgtADCWH',
                    'sign_name' => '粉心',
                ],

            ],
        ];

        $easySms = new EasySms($config);
        $loading = mt_rand(1,100);
        $num = mt_rand(0,9);
        $easySms->send(18677218429, [
            'template' => 'SMS_93960001',
            'data' => [
                'name' => '帅气的Charles',
                'day' => '今天',
                'num'  => $num,
                'title' => 'Wechat商城系统',
                'loading' => $loading,
            ],
        ]);
    }
}
